package com.shfl.rect;

import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Background;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * 遮罩层
 */
public class DialogStage {

    private ProgressIndicator progressIndicator = new ProgressIndicator();
    private Stage dialogStage =  new Stage();


    public DialogStage(Stage parentStock, String promptMessage) {
        // 窗口父子关系
        dialogStage.initOwner(parentStock);
//        dialogStage.initStyle(StageStyle.UNDECORATED);
        dialogStage.initStyle(StageStyle.TRANSPARENT);
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        dialogStage.setX(parentStock.getX() + parentStock.getHeight()/2 );
        dialogStage.setY(parentStock.getY()+ parentStock.getWidth()/4 );
        // progress bar
        Label label = new Label(!"".equals(promptMessage.trim()) ? promptMessage.trim() : "数据加载中, 请稍后...");
        label.setTextFill(Color.BLUE);
        progressIndicator.setProgress(-1F);
        VBox vBox = new VBox();
        vBox.setSpacing(10);
        vBox.setBackground(Background.EMPTY);
        vBox.getChildren().addAll(progressIndicator, label);
        Scene scene = new Scene(vBox);
        scene.setFill(null);
        dialogStage.setScene(scene);
    }


    public void activateProgressBar() {
        dialogStage.show();
    }

    public void cancelProgressBar() {
        dialogStage.close();
    }

}
